package com.jsh.erp.aop;

import com.jsh.erp.exception.AuthExpiredException;
import com.jsh.erp.utils.AuthCache;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class WebControllerAop {
    /**
     * 指定切点
     * 匹配 com.example.demo.controller包及其子包下的所有类的所有方法
     */
    @Pointcut("execution(public * com.jsh.erp.controller.*.*(..))")
    public void  optlog(){
    }

    /**
     * 前置通知，方法调用前被调用
     * @param joinPoint
     */
    @Before("optlog()")
    public void doBefore(JoinPoint joinPoint) throws Exception{
        if (AuthCache.isExpired) {
            throw new AuthExpiredException();
        }
    }
}
